{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ee63f986",
   "metadata": {},
   "source": [
    "# 群丛文件夹"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "32f61edb",
   "metadata": {},
   "outputs": [],
   "source": [
    "source_path = r\"E:\\毕业论文\\265_雪层杜鹃、髯花杜鹃灌丛\"\n",
    "\n",
    "空间分布mxd名字 = \"265_雪层杜鹃、髯花杜鹃灌丛_寒温带.mxd\"\n",
    "图斑shp名字 = \"415_雪层杜鹃、髯花杜鹃灌丛.dbf\"\n",
    "#随便挑一个地域mxd,shp复制过来就行\n",
    "\n",
    "占位图路径 = \"ncepu.jpg\" #什么图都行，是图就行\n",
    "\n",
    "压缩比例 = 0.1 #降低文件大小\n",
    "\n",
    "zhibei_total=r'0_植被群系1621汇总.xlsx'\n",
    "\n",
    "群系过长 = False #如果群系名称很长很长而且有很长很长的温度带，改成True "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6befbd05",
   "metadata": {},
   "outputs": [],
   "source": [
    "雪层杜鹃、髯花杜鹃灌丛+硬叶柳灌丛\n",
    "雪层杜鹃、髯花杜鹃灌丛+金露梅灌丛\n",
    "雪层杜鹃、髯花杜鹃灌丛+箭叶锦鸡儿灌丛\n",
    "雪层杜鹃、髯花杜鹃灌丛+腋花杜鹃灌丛\n",
    "雪层杜鹃、髯花杜鹃灌丛+香柏、高山柏、滇藏方枝柏灌丛\n",
    "雪层杜鹃、髯花杜鹃灌丛+小嵩草草甸\n",
    "雪层杜鹃、髯花杜鹃灌丛+小嵩草草甸\n",
    "雪层杜鹃、髯花杜鹃灌丛+小嵩草、紫花针茅草甸\n",
    "雪层杜鹃、髯花杜鹃灌丛+小嵩草、圆穗蓼草甸\n",
    "雪层杜鹃、髯花杜鹃灌丛+云南嵩草、杂类草草甸\n",
    "雪层杜鹃、髯花杜鹃灌丛+圆穗蓼、珠芽蓼草甸\n",
    "雪层杜鹃、髯花杜鹃灌丛\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7809f9f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "def creat_name(list_name):\n",
    "    a=''\n",
    "    for i in range(len(list_name)):\n",
    "        b=''\n",
    "        aluee_name=str(list_name.iloc[i,1])\n",
    "        book_name=str(list_name.iloc[i,12])\n",
    "        b=b+aluee_name+book_name\n",
    "        if i+1!=len(list_name):\n",
    "             b=b+'、'\n",
    "        a=a+b\n",
    "    return a \n",
    "#4锁表格\n",
    "def wentai(a):\n",
    "    return a>=63.21\n",
    "def yawentai(a):\n",
    "    return a<63.21 and a>=36.79\n",
    "def hundun(a):\n",
    "    return a<36.79"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ecd8d3f3",
   "metadata": {},
   "source": [
    "# 对群丛文件的预处理，保证没有打开任何群丛文件夹中的文件、文件夹（很重要）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ef71bb98",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"\n",
    "如果报错，就关掉所有打开的文件、文件夹，然后再运行，直到不报错为止\n",
    "\"\"\"\n",
    "\n",
    "\n",
    "\n",
    "savecode,savename = 空间分布mxd名字.split(\"_\")[:2]\n",
    "polycode,polyname = 图斑shp名字.split(\"_\")[:2]\n",
    "\n",
    "def rep(st):\n",
    "    if not 群系过长:\n",
    "        return st\n",
    "    st = st.replace(savecode,\"scode\")\n",
    "    st = st.replace(savename,\"sname\")\n",
    "    st = st.replace(polycode,\"pcode\")\n",
    "    st = st.replace(polyname,\"pname\")\n",
    "    return st\n",
    "\n",
    "import os\n",
    "for root,dirs,files in os.walk(source_path,topdown=False): \n",
    "    for file in files:\n",
    "        filename_path=os.path.join(root,file)\n",
    "        new_filename = rep(file)\n",
    "        new_filename_path=os.path.join(root,new_filename)\n",
    "        try:\n",
    "            os.rename(filename_path,new_filename_path)\n",
    "        except:\n",
    "            pass\n",
    "    for dir in dirs:\n",
    "        dir_path=os.path.join(root,dir)\n",
    "        new_dir = rep(dir)\n",
    "        new_dir_path=os.path.join(root,new_dir)\n",
    "        try:\n",
    "            os.rename(dir_path,new_dir_path)\n",
    "        except:\n",
    "            pass\n",
    "filelist = []\n",
    "for root,dirs,files in os.walk(source_path,topdown=False): \n",
    "    for file in files:\n",
    "        filename_path=os.path.join(root,file)\n",
    "        filelist.append(filename_path)\n",
    "\n",
    "        \n",
    "        \n",
    "\n",
    "reverse = {'1': '1', 'nan': '586k', '576': '3', '861': '4', '1194': '5', '1462': '7', '1496': '8', '1528': '9', '1557': '10', '25': '12', '50': '13', '61': '14', '78': '15', '91': '16', '106': '17', '20': '11a', '23': '11b', '232': '1a', '234': '1b', '235': '1c', '236': '1d', '571': '2a', '574': '2b', '575': '2c', '1526': '8a', '1527': '8b', '22': '11a+10', '24': '11b+10', '92': '16+14', '26': '12+18', '62': '14+18', '27': '12+85', '573': '2a+353', '21': '11a+11b', '862': '4+71a', '233': '1a+89a', '863': '4+89a', '1558': '10+89b', '79': '15+zero', '572': '2a+zero', '121': '18', '148': '19', '195': '20', '237': '21', '270': '22', '298': '23', '272': '22+77', '126': '18+79', '273': '22+79', '127': '18+85', '299': '23+194', '300': '23+201', '124': '18+385', '123': '18+370a', '271': '22+429b', '125': '18+72a', '128': '18+93b', '122': '18+zero', '321': '24', '381': '25', '405': '26', '429': '27', '459': '28', '492': '29', '520': '30', '577': '31', '612': '32', '340': '24a', '350': '24b', '364': '24c', '375': '24d', '402': '25c', '517': '29b', '518': '29a', '395': 'zero', '396': 'zero', '401': 'zero', '403': 'zero', '514': 'zero', '516': 'zero', '519': 'zero', '341': '24a+20', '345': '24a+31', '357': '24b+31', '369': '24c+31', '348': '24a+77', '515': 'zero+85', '362': '24b+97', '349': '24a+99', '363': '24b+99', '578': '31+104', '352': '24b+119', '580': '31+119', '365': '24c+120', '366': '24c+138', '367': '24c+189', '342': '24a+210', '343': '24a+213', '353': '24b+213', '397': 'zero+214', '581': '31+215', '355': '24b+225', '368': '24c+228', '398': 'zero+272', '351': '24b+108a', '579': '31+113c', '354': '24b+224a', '356': '24b+24a', '344': '24a+24b', '582': '31+24d', '346': '24a+430a', '358': '24b+431a', '370': '24c+431a', '376': '24d+431a', '583': '31+431a', '359': '24b+434a', '371': '24c+434a', '378': '24d+434a', '399': 'zero+439b', '347': '24a+75a', '404': 'zero+zero', '635': '33', '654': '34', '669': '35', '696': '36', '739': '37', '767': '38', '794': '39', '847': '40', '864': '41', '892': '42', '939': '43', '1005': '44', '1017': '45', '1031': '46', '1065': '47', '1090': '48', '1112': '49', '1157': '50', '1195': '51', '1222': '52', '1235': '53', '1252': '54', '1265': '55', '1286': '56', '1336': '57', '1391': '58', '1460': '59', '1461': '60', '1463': '61', '1467': '62', '1468': '63', '671': '35+68d+145', '940': '43+12', '848': '40+35', '941': '43+42', '893': '42+43', '1236': '53+46', '1466': '61+46', '894': '42+51', '942': '43+51', '1114': '49+51', '865': '41+52', '1033': '46+54', '1034': '46+55', '1066': '47+55', '1237': '53+56', '1067': '47+58', '1035': '46+61', '1036': '46+63', '895': '42+85', '896': '42+88', '1032': '46+142', '1464': '61+202', '1113': '49+254', '697': '36+257', '1465': '61+241a', '670': '35+68d', '1091': '48+zero', '1469': '64', '1470': '64a', '1471': '64b', '1472': '64c', '1473': '64d', '1474': '64e', '1475': '65', '1476': '66', '1478': '68b', '1479': '68c', '1480': '68d', '1477': 'zero', '1481': '69', '1486': '70', '1489': '71', '1497': '72', '1504': '73', '1505': '74', '1506': '75', '1510': '76', '1512': '77', '1520': '78', '1521': '79', '1523': '80', '1524': '81', '1529': '82', '1531': '83', '1533': '84', '1535': '85', '1543': '86', '1544': '87', '1545': '88', '1546': '89', '1555': '90', '1556': '91', '1559': '92', '1483': '69a', '1484': '69b', '1490': '71a', '1493': '71b', '1495': '71c', '1499': '72a', '1503': '72b', '1507': '75a', '1509': '75b', '1547': '89a', '1553': '89b', '1552': '89a+85+18', '1536': '85+18', '1522': '79+22', '1482': '69+70', '1485': '69b+70', '1515': '77+75', '1516': '77+76', '1511': '76+77', '1517': '77+78', '1488': '70+81', '1518': '77+82', '1538': '85+82', '1525': '81+83', '1498': '72+85', '1502': '72a+85', '1551': '89a+85', '1554': '89b+85', '1539': '85+88', '1540': '85+89', '1519': '77+96', '1500': '72a+190', '1548': '89a+192', '1491': '71a+194', '1537': '85+194', '1508': '75a+195', '1501': '72a+196', '1530': '82+196', '1487': '70+520', '1549': '89a+1a', '1513': '77+24a', '1534': '84+370a', '1494': '71b+71a', '1492': '71a+71b', '1550': '89a+72a', '1541': '85+89a', '1542': '85+89b', '1560': '93', '1576': '94', '1579': '95', '1563': '93a', '1570': '93b', '1575': '93c', '1571': '93b+18', '1578': '94+95', '1564': '93a+184', '1577': '94+287', '1561': '93+379', '1565': '93a+382', '1566': '93a+390', '1562': '93+391', '1567': '93a+391', '1573': '93b+391', '1574': '93b+468', '1568': '93a+485', '1572': '93b+199a', '1580': '96', '1581': '97', '1588': '98', '1589': '99', '1600': '100', '1602': '101', '2': '102', '5': '103', '7': '104', '8': '105', '9': '106', '11': '107', '10': 'zero', '1585': '97+99+102', '1586': '97+99+103', '1593': '99+18', '1597': '99+31', '12': '107+59', '1584': '97+99', '1587': '97+101', '1599': '99+101', '1582': '97+102', '1590': '99+104', '3': '102+118', '6': '103+118', '4': '102+120', '1592': '99+120', '1601': '100+431', '1598': '99+433', '1591': '99+108a', '1583': '97+224a', '1594': '99+24a', '1595': '99+24b', '1596': '99+zero', '13': '108', '17': '109', '18': '110', '28': '111', '29': '113', '34': '114', '14': '108a', '15': '108b', '16': '108c', '30': '113a', '31': '113b', '32': '113c', '33': '113d', '19': 'zero', '35': '118', '37': '130', '38': '119', '43': '120', '45': '121', '49': '122', '51': '123', '52': '124', '53': '125', '55': '126', '56': '127', '57': '128', '58': '133', '60': '129', '69': '132', '70': '134', '71': '131', '41': '119+24b+169', '39': '119+120', '40': '119+129', '72': '131+214', '36': '118+24b', '44': '120+24c', '42': '119+431a', '46': '136', '54': '137', '59': '140', '63': '138', '68': '139', '73': '141', '64': '138+119', '65': '138+120', '66': '138+24c', '47': '136+431a', '67': '138+431a', '74': '142', '75': '143', '76': '144', '77': '145', '80': '146', '81': '147', '82': '148', '83': '149', '84': '150', '86': '151', '87': '152', '96': '153', '85': '150+431a', '88': '158', '89': '155', '97': '159', '100': '161', '101': '162', '102': '163', '103': '164', '104': '165', '105': '166', '107': '167', '108': '168', '94': '157a', '95': '157b', '90': 'zero', '98': 'zero', '99': 'zero+431a', '93': 'zero+zero', '109': '169', '111': '170', '112': '171', '116': '172', '117': '173', '118': '174', '119': '175', '120': '176', '129': '177', '131': '178', '132': '179', '133': '180', '134': '181', '135': '182', '113': '171a', '114': '171b', '115': '171c', '130': '177+179', '110': '169+zero', '1621': '234a', '136': '183', '137': '184', '139': '185', '143': '186', '149': '187', '152': '188', '153': '189', '160': '190', '162': '191', '163': '192', '168': '193', '169': '194', '185': '195', '186': '196', '196': '198', '197': '198a', '198': '198b', '199': '199', '200': '199a', '205': '199b', '208': '199c', '209': '199d', '210': '200', '214': '201', '218': '202', '219': '203', '220': '204', '221': '205', '428': '267', '430': '269', '431': '270', '435': '271', '436': '272', '323': '239', '324': '240', '326': '241', '327': '241a', '329': '242', '330': '243', '331': '244', '332': '245', '333': '246', '339': '247', '382': '248', '384': '249', '385': '250', '386': '251', '387': '252', '388': '253', '390': '254', '391': '256', '393': '257', '406': '258', '407': '259', '408': '260', '409': '261', '411': '262', '412': '263', '413': '264', '415': '265', '427': '266', '224': '206', '228': '207', '238': '208', '240': '209', '241': '210', '242': '211', '243': '212', '244': '213', '251': '214', '252': '215', '260': '216', '267': '217', '274': '218', '275': '219', '277': '220', '278': '220a', '280': '220b', '281': '221', '282': '222', '283': '223', '284': '224a', '286': '224b', '287': '224c', '288': '225', '296': '226', '297': '227', '301': '228', '306': '229', '309': '230', '310': '230a', '311': '230b', '312': '231', '313': '232', '314': '233', '316': '235', '319': '236', '320': '237', '322': '238', '138': '184+391', '140': '185+18', '142': '185+71a', '144': '186+192', '145': '186+194', '146': '186+75a', '147': '186+89a', '150': '187+366', '151': '187+368', '154': '189+188', '155': '189+190', '156': '189+192', '157': '189+195', '158': '189+429a', '159': '189+72a', '161': '190+196', '164': '192+194', '165': '192+196', '166': '192+200', '167': '192+389', '170': '194+18', '171': '194+185', '172': '194+187', '173': '194+190', '174': '194+192', '175': '194+196', '176': '194+200', '177': '194+357', '178': '194+366', '179': '194+388', '180': '194+429a', '181': '194+429b', '183': '194+85', '184': '194+93b', '187': '196+18', '188': '196+194', '189': '196+200', '190': '196+23', '191': '196+389', '192': '196+429a', '193': '196+429b', '194': '196+465b', '201': '199a+199b', '202': '199a+391', '203': '199a+468', '204': '199a+93b', '206': '199b+390', '207': '199b+394', '211': '200+194', '212': '200+196', '215': '201+18', '216': '201+189', '217': '201+194', '222': '205+479', '223': '205+488', '432': '270+245', '433': '270+497a', '434': '270+497d', '325': '240+257', '328': '241a+257', '334': '246+241', '335': '246+241a', '336': '246+499', '337': '246+499a', '338': '246+513', '383': '248+415a', '389': '253+415a', '392': '256+254', '394': '257+241', '410': '261+244', '414': '264+263', '416': '265+240', '417': '265+246', '418': '265+251', '419': '265+264', '420': '265+270', '421': '265+497', '422': '265+497a', '423': '265+497b', '424': '265+497d', '425': '265+501', '426': '265+513', '225': '206+207', '226': '206+213', '227': '206+431a', '229': '207+103', '230': '207+206', '231': '207+213', '239': '208+433', '245': '213+118', '246': '213+225', '247': '213+24b', '248': '213+431a', '249': '213+434a', '253': '215+153', '254': '215+24b', '255': '215+24c', '256': '215+24d', '257': '215+431a', '258': '215+436', '261': '216+24d', '262': '216+436', '279': '220a+216', '285': '224a+24b', '289': '225+113a', '290': '225+213', '291': '225+24b', '292': '225+431a', '293': '225+437a', '302': '228+24c', '303': '228+431a', '304': '228+434a', '307': '229+164', '308': '229+431a', '317': '235+219', '919': '429', '920': '429+370a', '921': '429a', '922': '429a+189', '923': '429a+370a', '924': '429a+389', '925': '429a+429b', '926': '429a+430a', '927': '429a+430b', '928': '429a+465b', '931': '429b', '932': '429b+188', '933': '429b+192', '934': '429b+194', '935': '429b+22', '936': '429b+491', '938': '429b+77', '943': '430', '944': '430a', '945': '430b', '947': '430c', '948': '431', '949': '431a', '950': '431a+119', '951': '431a+120', '952': '431a+138', '953': '431a+150', '954': '431a+208', '955': '431a+213', '956': '431a+215', '957': '431a+225', '958': '431a+228', '959': '431a+24a', '960': '431a+24b', '961': '431a+24c', '962': '431a+24c+120', '963': '431a+24d', '964': '431a+25c', '965': '431a+31', '967': '431b', '968': '431b+438', '969': '432', '970': '433', '971': '433+99', '972': '434', '973': '434a', '974': '434a+213', '975': '434a+215', '976': '434a+225', '977': '434a+24b', '978': '434a+24c', '979': '434a+24d', '984': '434b', '986': '435', '987': '436', '988': '436+215', '989': '436+216', '993': '437', '994': '437a', '995': '437a+431a', '996': '437a+433', '997': '437a+439b', '998': '437b', '999': '437b+431a', '1000': '438', '1001': '439a', '1002': '439b', '1003': '439b+431a', '1004': '439b+434b', '1006': '440', '1007': '442', '1008': '443', '1009': '444a', '1010': '444b', '679': '352', '685': '353', '686': '354', '687': '355', '688': '356', '689': '357', '695': '358', '698': '360', '699': '360a', '700': '360b', '701': '361', '702': '362', '703': '363', '705': '364', '706': '365', '707': '366', '684': '352+83', '690': '357+193', '691': '357+194', '708': '366+194', '709': '366+352', '710': '366+357', '680': '352+366', '692': '357+366', '681': '352+368', '711': '366+368', '682': '352+391', '693': '357+392', '712': '366+464', '714': '367', '722': '368', '730': '369', '740': '370', '741': '370a', '752': '370b', '753': '371', '754': '371a', '755': '371b', '756': '372', '757': '373', '758': '374', '759': '375', '760': '376', '762': '376a', '763': '376b', '764': '377', '765': '378', '766': '379', '768': '380', '771': '381', '772': '382', '779': '384', '780': '385', '784': '386', '785': '387', '786': '387a', '787': '387b', '790': '388', '793': '389', '795': '390', '799': '391', '778': 'zero', '747': '370a+427+428', '742': '370a+18', '808': '391+82', '792': '388+85', '751': '370a+93', '743': '370a+194', '791': '388+201', '801': '391+307', '773': '382+314', '715': '367+352', '802': '391+352', '723': '368+357', '731': '369+358', '716': '367+366', '724': '368+366', '725': '368+367', '732': '369+367', '717': '367+368', '733': '369+368', '718': '367+369', '726': '368+369', '769': '380+369', '774': '382+369', '804': '391+379', '727': '368+382', '734': '369+382', '788': '387b+382', '744': '370a+385', '728': '368+386', '745': '370a+389', '781': '385+389', '805': '391+390', '797': '390+391', '735': '369+392', '776': '382+392', '736': '369+393', '737': '369+394', '746': '370a+396', '770': '380+407', '761': '376+414', '748': '370a+428', '806': '391+460', '720': '367+483', '800': '391+199a', '796': '390+199b', '803': '391+370a', '775': '382+387b', '719': '367+zero', '789': '387b+zero', '807': '391+zero', '809': '392', '819': '393', '822': '394', '832': '395', '840': '396', '841': '397', '842': '398', '845': '399', '849': '400', '850': '401', '852': '402a', '853': '402b', '854': '403', '855': '404', '856': '405', '857': '406', '858': '407', '860': '409', '866': '410', '870': '411', '871': '412', '872': '413', '874': '414', '859': 'zero', '810': '392+201', '833': '395+282', '811': '392+297', '812': '392+302', '834': '395+302', '851': '401+305', '824': '394+307', '835': '395+307', '836': '395+333', '813': '392+342', '825': '394+375', '826': '394+378', '820': '393+382', '867': '410+390', '821': '393+392', '827': '394+392', '838': '395+392', '814': '392+393', '815': '392+394', '816': '392+395', '828': '394+395', '829': '394+396', '873': '413+399', '817': '392+401', '830': '394+403', '844': '398+403', '846': '399+404', '831': '394+407', '869': '410+409', '818': '392+411', '839': '395+412', '823': '394+305b', '843': '398+324a', '837': '395+370a', '868': '410+402b', '875': '415', '876': '415a', '883': '415b', '884': '415c', '885': '415d', '886': '415e', '889': '417', '890': '418', '891': '419', '897': '420', '898': '421', '899': '422', '900': '423', '901': '424', '904': '425', '905': '426', '906': '426a', '908': '426b', '912': '426c', '913': '427', '916': '428', '915': '427+428+370a', '917': '428+251', '909': '426b+350', '902': '424+394', '879': '415a+427', '903': '424+427', '914': '427+428', '882': '415a+516', '911': '426b+548', '918': '428+370a', '877': '415a+371a', '907': '426a+415a', '910': '426b+415a', '888': 'zero+415a', '878': '415a+426a', '887': '415e+426b', '880': '415a+497a', '881': '415a+508a', '437': '273', '451': '274', '439': '273a', '445': '273b', '447': '273c', '449': '273d', '440': '273a+274', '441': '273a+285', '442': '273a+289', '450': '273d+289', '443': '273a+302', '448': '273c+318', '452': '274+328', '438': '273+330', '444': '273a+330', '446': '273b+330', '453': '275', '457': '277', '460': '278', '461': '279', '462': '280', '466': '281', '469': '282', '472': '283', '473': '284', '478': '285', '483': '286', '486': '287', '493': '288', '495': '289', '501': '290', '503': '292', '500': 'zero', '470': '282+285+275', '491': '287+94', '479': '285+205', '496': '289+205', '487': '287+272', '484': '286+273', '497': '289+275', '488': '287+285', '502': '290+285', '471': '282+287', '481': '285+287', '485': '286+290', '474': '284+296', '498': '289+302', '458': '277+312', '455': '275+318', '468': '281+328', '475': '284+329', '494': '288+331', '476': '284+337', '489': '287+338', '482': '285+479', '490': '287+479', '477': '284+483', '467': '281+273a', '480': '285+273a', '463': '280+308a', '464': '280+308b', '499': '289+376b', '465': '280+415a', '456': '275+93a', '454': '275+zero', '504': '293', '505': '294', '506': '295', '507': '296', '510': '297', '513': '298', '521': '299', '522': '300', '523': '301', '511': '297+289', '508': '296+295', '509': '296+302', '512': '297+93c', '524': '302', '543': '302a', '544': '302b', '546': '302c', '547': '303', '549': '304', '550': '305', '554': '305a', '555': '305b', '557': '305c', '558': '306', '560': '307', '564': '308', '568': '308a', '570': '308b', '584': '309', '585': '310', '586': '311', '587': '312', '600': '313', '601': '314', '602': '315', '604': '316', '606': '316a', '608': '317', '609': '318', '613': '319', '614': '320', '615': '321', '619': '322', '620': '323', '621': '324', '622': '324a', '624': '324b', '625': '325', '626': '326', '631': '326b', '629': '326c', '632': '327', '633': '328', '636': '329', '641': '330', '643': '331', '644': '332', '645': '333', '647': '334', '648': '335', '649': '336', '650': '337', '596': '312e', '597': '312b', '599': '312c', '611': 'zero', '616': 'zero', '618': 'zero', '630': 'zero', '535': '302+312+275', '529': '302+289+312', '525': '302+275', '548': '303+275', '603': '315+275', '588': '312+282', '637': '329+284', '526': '302+287', '527': '302+288', '528': '302+289', '545': '302b+289', '565': '308+289', '530': '302+294', '561': '307+296', '642': '330+296', '531': '302+297', '638': '329+297', '551': '305+302', '559': '306+302', '562': '307+302', '552': '305+303', '566': '308+305', '532': '302+306', '589': '312+306', '598': '312b+306', '533': '302+307', '590': '312+307', '534': '302+312', '563': '307+312', '627': '326+312', '591': '312+316', '592': '312+318', '593': '312+326', '628': '326+327', '536': '302+329', '537': '302+330', '639': '329+330', '556': '305b+333', '538': '302+335', '594': '312+335', '605': '316+335', '607': '316b+335', '610': '318+338', '539': '302+340', '553': '305+342', '567': '308+342', '569': '308a+342', '540': '302+392', '541': '302+410', '634': '328+460', '640': '329+460', '542': '302+479', '623': '324a+483', '646': '333+305b', '595': '312+93a', '617': 'zero+zero', '651': '338', '655': '339', '656': '340', '658': '341', '659': '342', '660': '343', '661': '344', '662': '345', '652': '338+287', '663': '345+287', '657': '340+290', '653': '338+326', '664': '345+340', '665': '345+344', '666': '346', '667': '347', '668': '348', '672': '349', '673': '350', '677': '351', '676': '350+516', '678': '351+516', '674': '350+387b', '675': '350+426b', '1011': '445', '1013': '446', '1014': '447', '1015': '448', '1016': '449', '1018': '450', '1019': '452', '1020': '452b', '1023': '453', '1024': '454', '1025': '455', '1026': '456', '1027': '457', '1029': '458', '1030': '459', '1037': '460', '1039': '461', '1041': '464', '1043': '465', '1049': '465a', '1051': '465b', '1040': 'zero', '1053': 'zero', '1050': 'zero', '1048': '465+81', '1044': '465+185', '1042': '464+366', '1038': '460+385', '1021': '452b+445', '1012': '445+458', '1022': '452b+468', '1045': '465+468', '1028': '457+499', '1046': '465+520', '1054': '467', '1055': '468', '1062': '469', '1063': '469a', '1064': '469b', '1068': '470', '1069': '471', '1070': '472', '1071': '472a', '1072': 'zero', '1074': '474', '1075': '475', '1076': 'zero', '1061': '468+70', '1056': '468+445', '1059': '468+520', '1057': '468+452b', '1058': '468+zero', '1073': 'zero+zero', '1077': 'zero+245', '1078': '477', '1079': '478', '1080': '479', '1092': '480', '1093': '481', '1097': '482', '1098': '483', '1101': '484', '1105': '485', '1106': '486', '1107': '487', '1108': '488', '1111': '489', '1115': '491', '1116': '492', '1119': '493', '1123': '494', '1128': '495', '1129': '496', '1089': '479a', '1094': '481a', '1096': '481b', '1125': '494a', '1127': '494b', '1130': '496a', '1131': '496b', '1132': '496c', '1100': '483+81', '1081': '479+203', '1102': '484+203', '1103': '484+253', '1120': '493+275', '1082': '479+285', '1121': '493+285', '1126': '494a+285', '1083': '479+287', '1095': '481a+287', '1122': '493+287', '1084': '479+290', '1085': '479+344', '1109': '488+344', '1099': '483+479', '1104': '484+479', '1117': '492+479', '1086': '479+482', '1087': '479+483', '1088': '479+488', '1118': '492+481a', '1124': '494+481b', '1133': '496c+496b', '1110': '488+504a', '1134': '497', '1135': '497a', '1143': '497b', '1145': '497c', '1146': '497d', '1148': '498', '1151': '499', '1152': '499a', '1154': '499b', '1155': '499c', '1156': '500', '1158': '501', '1160': '502', '1161': '503', '1162': '503a', '1163': '503b', '1165': '503c', '1166': '503d', '1167': '503e', '1168': '504', '1169': '504a', '1172': '504b', '1179': '504c', '1184': '504d', '1185': '505', '1186': '506', '1188': '507', '1189': '508', '1190': '508a', '1191': '508b', '1192': '509', '1193': '510', '1196': '511', '1197': '511a', '1198': '511b', '1199': '511d', '1200': '511e', '1201': '512', '1202': '513', '1204': '514', '1205': '515', '1207': '516', '1213': '517', '1212': 'zero', '1144': '497b+504d+246', '1178': '504b+541+484', '1182': '504c+504b+541', '1174': '504b+504c+541', '1175': '504b+504c+542', '1137': '497a+43', '1180': '504c+203', '1208': '516+351', '1206': 'zero+351', '1159': '501+456', '1210': '516+479', '1138': '497a+498', '1164': '503b+498', '1142': '497a+516', '1177': '504b+541', '1183': '504c+541', '1211': '516+556', '1149': '498+241a', '1170': '504a+415a', '1209': '516+415a', '1136': '497a+426a', '1147': '497d+497a', '1150': '498+497a', '1153': '499a+497a', '1171': '504a+497a', '1203': '513+497a', '1139': '497a+499a', '1140': '497a+499c', '1141': '497a+504a', '1181': '504c+504b', '1173': '504b+504c', '1176': '504b+504d', '1187': '506+zero', '1254': '543', '1255': '544', '1256': '545', '1257': '546', '1258': '547', '1259': '548', '1262': '549', '1263': '550', '1264': '551', '1266': '552', '1267': '553', '1261': '548+516', '1260': '548+426a', '1268': '555', '1269': '556', '1270': '557', '1271': '558', '1273': '559', '1272': '558+548', '1214': '518', '1215': '518a', '1216': '520', '1217': '520+445', '1218': '520+465', '1219': '520+zero', '1220': '520+70', '1221': '520+85', '1223': '521', '1224': '522', '1225': '523', '1226': '524', '1227': '525', '1228': '526', '1229': '527', '1230': '528', '1231': '528a', '1232': '528b', '1233': '529', '1234': '530', '1238': '531', '1239': '532', '1240': '533', '1241': '534', '1242': '535', '1243': '536', '1244': '536+534', '1247': '537', '1248': '538', '1619': '536+537', '1620': '536+535', '1249': '540', '1250': '541', '1253': '542', '1251': '541+504b', '1274': '560', '1275': '561', '1276': '562', '1287': '563', '1301': '564', '1306': '565', '1307': '566', '1309': '567', '1310': '568', '1318': '569', '1322': '570', '1324': '571', '1337': '573', '1354': '574', '1355': '575', '1356': '576', '1357': '577', '1363': '578', '1366': '579', '1373': '580', '1374': '581', '1390': '582', '1392': '583', '1394': '584', '1415': '585', '1438': '586', '48': '136+585', '141': '185+562', '182': '194+571', '213': '200+569', '250': '213+581', '259': '215+584', '263': '216+584', '264': '216+585', '265': '216+586', '266': '216+586m', '268': '217+586', '269': '217+586m', '276': '219+586', '294': '225+581', '295': '225+584', '305': '228+584', '318': '235+586', '360': '24b+581', '361': '24b+584d', '372': '24c+584', '373': '24c+585', '374': '24c+586l', '377': '24d+431a+584', '379': '24d+584', '380': '24d+585', '400': 'zero+579', '683': '352+563', '694': '357+563', '704': '363+563', '713': '366+562', '721': '367+563', '729': '368+563', '738': '369+568', '749': '370a+563', '750': '370a+568', '777': '382+563', '782': '385+563', '783': '385+568', '798': '390+568', '929': '429a+569', '930': '429a+571', '937': '429b+570', '946': '430b+571', '1277': '562+185', '1278': '562+352', '1279': '562+366', '1280': '562+387b', '1281': '562+465', '1282': '562+468', '1283': '562+483', '1284': '562+520', '1285': '562a', '1288': '563+357', '1289': '563+367', '1290': '563+368', '1291': '563+370a', '1292': '563+385', '1293': '563+387b', '1294': '563+388', '1295': '563+569b', '1296': '563+82', '1297': '563+83', '1298': '563+85', '1299': '563a', '1300': '563a+571', '1302': '564+369', '1303': '564+390', '1304': '564+83', '1305': '564+85', '1308': '566+445', '1311': '568+182', '1312': '568+183', '1313': '568+369', '1314': '568+370a', '1315': '568+483', '1316': '568+84', '1317': '568+93b', '1319': '569+429a', '1320': '569a', '1321': '569b', '1323': '570+429b', '1325': '571+429a', '1326': '571+429b', '1327': '571+430b', '1328': '571a', '1329': '571a+571c', '1330': '571b', '1331': '571c', '1332': '571d', '1333': '571e', '1334': '571f', '1335': '571g', '1338': '573+24a', '1339': '573a', '1340': '573b', '1341': '573c', '1342': '573d', '1343': '573e', '1344': '573f', '1345': '573g', '1346': '573h', '1347': '573i', '1348': '573j', '1349': '573k', '1350': '573m', '1351': '573p', '1352': '573q', '1353': '573r', '1358': '577+206', '1359': '577a', '1360': '577b', '1361': '577c', '1362': '577d', '1364': '578+104', '1365': '578+224a', '1367': '579+182', '1368': '579+214', '1369': '579+zero', '1370': '579+434', '1371': '579+434a', '1372': '579+578', '1375': '581+213', '1376': '581+225', '1377': '581+31', '1378': '581+431a', '1379': '581+577', '1380': '581+581c', '1381': '581a', '1382': '581b', '1383': '581c', '1384': '581d', '1385': '581e', '1386': '581f', '1387': '581g', '1388': '581h', '1389': 'nan', '1393': '583a', '1395': '584+209', '1396': '584+215', '1397': '584+216', '1398': '584+228', '1399': '584+24b', '1400': '584+24c', '1401': '584+24d', '1402': '584+434a', '1403': '584a', '1404': '584b', '1405': '584c', '1406': '584d', '1408': '584f', '1409': '584g+584h', '1410': '584h', '1411': '584i', '1412': '584k', '1413': '584l', '1414': '584m', '1416': '585+215', '1417': '585+216', '1418': '585+24d', '1419': '585+437b', '1618': '585+585g', '1421': '585+585h', '1422': '585a', '1423': '585b', '1424': '585b+216', '1425': '585c', '1426': '585c+585g', '1427': '585c+586m', '1428': '585d', '1429': '585f', '1430': '585g', '1431': '585h', '1432': '585h+216', '1433': '585h+585', '1434': '585i', '1435': '585j', '1436': '585k', '1437': '585l', '1439': '586+219', '1440': '586+586d', '1441': '586+586j', '1442': '586+586m', '1443': '586b', '1444': '586b+586', '1445': '586c', '1446': '586c+586', '1447': '586d', '1448': '586d+586', '1449': '586d+586c', '1450': '586d+586i', '1451': '586e', '1452': '586f', '1453': '586g', '1454': '586h', '1455': '586i', '1456': '586l', '1458': '586m', '1459': '586n', '966': '431a+584', '980': '434a+581', '981': '434a+581f', '982': '434a+584', '983': '434a+585', '985': '434b+584', '990': '436+584', '991': '436+585h', '992': '436+586', '1047': '465+562', '1052': '465b+564', '1060': '468+562', '1407': '584d+584e', '1457': '586l+235', '1514': '77+577', '1532': '83+568', '1569': '93a+563'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f52d3d39",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "87136657",
   "metadata": {},
   "outputs": [],
   "source": [
    "def add(document,addtype,content,addto = None ,charsize = 1,picsize = (1,1),style = None,mid = False,bold = False,indent = 0):\n",
    "    if addto:\n",
    "        paragraph = addto\n",
    "    else:\n",
    "        paragraph = document.add_paragraph() # 添加新段落\n",
    "    \"\"\"if addtype == \"head\":\n",
    "        run = document.add_heading(content, headlevel)\n",
    "        run.bold = bold\n",
    "        run.font.size = Pt(charsize)\"\"\"\n",
    "    if addtype == \"char\":\n",
    "        run = paragraph.add_run(content,style=style)\n",
    "        run.bold = bold\n",
    "        run.font.size = Pt(charsize)\n",
    "        if mid:\n",
    "            paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER\n",
    "        if indent:\n",
    "            paragraph.paragraph_format.first_line_indent = Inches(indent)\n",
    "    elif addtype == \"pic\":\n",
    "        if picsize:\n",
    "            paragraph.add_run().add_picture(content, width=Cm(picsize[0]),height = Cm(picsize[1]))\n",
    "        else:\n",
    "            paragraph.add_run().add_picture(content)\n",
    "        if mid:\n",
    "            paragraph.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER\n",
    "    return paragraph\n",
    "\n",
    "\n",
    "import pandas as pd\n",
    "\n",
    "def set_cell_border(cell, **kwargs):\n",
    "    \"\"\"\n",
    "    Set cell`s border\n",
    "    Usage:\n",
    "    set_cell_border(\n",
    "        cell,\n",
    "        top={\"sz\": 12, \"val\": \"single\", \"color\": \"#FF0000\", \"space\": \"0\"},\n",
    "        bottom={\"sz\": 12, \"color\": \"#00FF00\", \"val\": \"single\"},\n",
    "        left={\"sz\": 24, \"val\": \"dashed\", \"shadow\": \"true\"},\n",
    "        right={\"sz\": 12, \"val\": \"dashed\"},\n",
    "    )\n",
    "    \"\"\"\n",
    "    tc = cell._tc\n",
    "    tcPr = tc.get_or_add_tcPr()\n",
    "\n",
    "    # check for tag existnace, if none found, then create one\n",
    "    tcBorders = tcPr.first_child_found_in(\"w:tcBorders\")\n",
    "    if tcBorders is None:\n",
    "        tcBorders = OxmlElement('w:tcBorders')\n",
    "        tcPr.append(tcBorders)\n",
    "\n",
    "    # list over all available tags\n",
    "    for edge in ('left', 'top', 'right', 'bottom', 'insideH', 'insideV'):\n",
    "        edge_data = kwargs.get(edge)\n",
    "        if edge_data:\n",
    "            tag = 'w:{}'.format(edge)\n",
    "\n",
    "            # check for tag existnace, if none found, then create one\n",
    "            element = tcBorders.find(qn(tag))\n",
    "            if element is None:\n",
    "                element = OxmlElement(tag)\n",
    "                tcBorders.append(element)\n",
    "\n",
    "            # looks like order of attributes is important\n",
    "            for key in [\"sz\", \"val\", \"color\", \"space\", \"shadow\"]:\n",
    "                if key in edge_data:\n",
    "                    element.set(qn('w:{}'.format(key)), str(edge_data[key]))\n",
    "\n",
    "\n",
    "\n",
    "def temperature_template(bandname):\n",
    "    global piccode,filelist\n",
    "    #获取地域\n",
    "    arealist = []\n",
    "    for i in filelist:\n",
    "        if \"_\" + bandname + \"_\" in i:\n",
    "            c = re.findall(r\"地域([0-9]{1,2})\",i)\n",
    "            arealist += c\n",
    "    arealist = list(set(arealist))\n",
    "    arealist.sort(key = lambda x:int(x))\n",
    "    #print(bandname,\"arealist:\",arealist)\n",
    "    for areacode in arealist:\n",
    "        area_template(bandname,areacode)\n",
    "        \n",
    "def area_template(bandname,areacode):\n",
    "    global piccode,filelist,tablecode\n",
    "    \n",
    "    typelist = []\n",
    "    for i in filelist:\n",
    "        try:\n",
    "            if \"_\" + bandname+ \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\".\")[1] == areacode:\n",
    "                typelist.append(i)\n",
    "            elif \"-\" in i and \"_\" + bandname+ \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\"-\")[1] == areacode:\n",
    "                typelist.append(i)\n",
    "            if \"_\" + bandname.replace(\"交错带\",\"\") + \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\".\")[1] == areacode:\n",
    "                typelist.append(i)\n",
    "            elif \"-\" in i and \"_\" + bandname.replace(\"交错带\",\"\") + \"\\\\\" in i and \"类型csv\" in i and i.endswith(\".csv\") and i.split(\"\\\\\")[-1].split(\"-\")[1] == areacode:\n",
    "                typelist.append(i)\n",
    "        except:\n",
    "            print(\"文件异常：\" ,i.split(\"\\\\\")[-1])\n",
    "    typelist = list(set(typelist))\n",
    "    try:\n",
    "        typelist.sort(key = lambda x:int(x.split(\"\\\\\")[-1].split(\".\")[3]))\n",
    "    except:\n",
    "        typelist.sort(key = lambda x:int(x[:-4].split(\"\\\\\")[-1].split(\"-\")[2]))\n",
    "    print(f\"{bandname}地域{areacode}\")\n",
    "    #温度带地域简介1\n",
    "    text = savename + f\"{bandname}地域{areacode}位于横断山脉以西，唐古拉山以南。\"\n",
    "    para = add(document,\"char\",text,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "    #2\n",
    "    def changetypecsv(char):\n",
    "        if \"_\" not in char:\n",
    "            return char.replace(\".0.\",\".\").replace(\".\",\"-\")\n",
    "        else:\n",
    "            key = char.split(\"_\")[-1]\n",
    "            return key + \"-\" + char.split(\"_\")[0].split(\".\")[1] + \"-\" + char.split(\"_\")[0].split(\".\")[3]\n",
    "    \n",
    "    t = \"、\".join(changetypecsv(i.split(\"\\\\\")[-1][:-4]) for i in typelist)\n",
    "    print(t)\n",
    "    text = f\"有{len(typelist)}个群丛分布（群丛{t}）\"\n",
    "    para = add(document,\"char\",text,addto = para ,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "    #3\n",
    "    maxtb,mintb,maxdem,mindem,maxE,minE = 0,30,-999,99999,-99999,99999\n",
    "    for i in typelist:\n",
    "        df = pd.read_csv(i,engine='python')\n",
    "        maxtb = max(maxtb,max(df[\"tb\"]))\n",
    "        maxdem = max(maxdem,max(df[\"dem\"]))\n",
    "        maxE = max(maxE,max(df[\"E_sum\"]))\n",
    "        mintb = min(mintb,min(df[\"tb\"]))\n",
    "        mindem = min(mindem,min(df[\"dem\"]))\n",
    "        minE = min(minE,min(df[\"E_sum\"]))\n",
    "\n",
    "    maxtb = int(maxtb) + 1\n",
    "    mintb = int(mintb)\n",
    "    \n",
    "    maxdem = 100* (int(maxdem/100) + 1)\n",
    "    mindem = 100* (int(mindem/100) )\n",
    "    \n",
    "    maxE = 10* (int(maxE/10) + 1)\n",
    "    minE = 10* (int(minE/10) )\n",
    "    \n",
    "    text = f\"海拔在{mindem}至{maxdem}m之间，年生物学温度TB介于{mintb}至{maxtb}℃之间，能量E的范围在{minE}至{maxE}cm之间。\"\n",
    "    add(document,\"char\",text,addto = para ,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "    pic1 = 占位图路径\n",
    "    #图2a 图2b 海拔图，能量图\n",
    "    for i in filelist:\n",
    "        \n",
    "        if i.endswith(f\"{bandname}_地域{areacode}_海拔图.png\") or i.endswith(f\"{bandname}_地域{areacode}_海拔.png\"):\n",
    "            img = Image.open(i)\n",
    "            c = img.resize((int(img.size[0]*压缩比例),int(img.size[1]*压缩比例)))\n",
    "            c.save(\"temp.png\")\n",
    "            pic1 = \"temp.png\"\n",
    "\n",
    "        #if i.endswith(f\"{bandname}_地域{areacode}_温度能量.png\") or i.endswith(f\"{bandname}_地域{areacode}_温度能量图.png\"):\n",
    "            #pic2 = i\n",
    "            \n",
    "    para = add(document,\"pic\",pic1,picsize = (7.1,5.81),mid = True)\n",
    "    \n",
    "    #add(document,\"pic\",pic2,addto = para ,picsize = (7.1,5.81),mid = True)\n",
    "    \n",
    "    \"\"\"\n",
    "    text = \"(a)海拔分布图                     (b)能量温度分布图\"\n",
    "    add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "    \"\"\"\n",
    "    text = f\"图{piccode} {savename}{bandname}地域{areacode}分布图\"\n",
    "    piccode += 1\n",
    "    add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "    #print(\"type\",typelist)\n",
    "    #总表格\n",
    "    text = f\"表{tablecode} 地域{areacode}群丛状态统计表\"\n",
    "    tablecode += 1\n",
    "    add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "\n",
    "    tabledata = []\n",
    "    for typ in typelist:\n",
    "        df = pd.read_csv(typ,engine='python')\n",
    "        newname = changetypecsv(typ.split(\"\\\\\")[-1][:-4])\n",
    "        lines = []\n",
    "        for j in filelist:\n",
    "            if newname + \".svg\" in j:\n",
    "                with open(j, 'r',encoding = \"utf8\") as f:\n",
    "                    c = f.read()\n",
    "                    lines = re.findall(\"<!-- (E=.*?) -->\",c) + re.findall(\"<!-- (TB=.*?) -->\",c)\n",
    "                break  \n",
    "        if not lines:\n",
    "            print(f\"没查到群丛{newname}.svg中的斜率\")\n",
    "                    \n",
    "        d3_line = []\n",
    "        for line in lines:\n",
    "            if \"P\" not in line:\n",
    "                P = \"*\"\n",
    "                if re.findall(\"\\(R²=(.*?)\\)\",line):\n",
    "                    R = re.findall(\"\\(R²=(.*?)\\)\",line)[0]\n",
    "                else:\n",
    "                    R = \"\\\\\"\n",
    "            else:\n",
    "                P = re.findall(\"\\(.*?,(P.*?)\\)\",line)[0]\n",
    "                if re.findall(\"\\(R²=(.*?),.*?\\)\",line):\n",
    "                    R = re.findall(\"\\(R²=(.*?),.*?\\)\",line)[0]\n",
    "                else:\n",
    "                    R = \"\\\\\"\n",
    "            d3_line.append([line.split(\"(\")[0],R,P])    \n",
    "        pointnum = len(df)\n",
    "        a,b = round(sum(df[\"tb\"])/len(df),2),round(sum(df[\"E_sum\"])/len(df),2)\n",
    "        \n",
    "        tabledata.append([newname,pointnum,\"\\n\".join(asas[0] for asas in d3_line),\"\\n\".join(asas[1] for asas in d3_line),\"\\n\".join(asas[2] for asas in d3_line),(a,b),\"\"])\n",
    "        \n",
    "    tabledata.sort(key = lambda x : int(x[0].split(\"-\")[-1]))\n",
    "    table = document.add_table(rows=1, cols=7,style=None)\n",
    "    table.alignment=WD_TABLE_ALIGNMENT.CENTER\n",
    "\n",
    "    #写标题行，并设置字体\n",
    "    \n",
    "    hdr_cells = table.rows[0].cells\n",
    "    Fields=\"编号\t样本点数\t拟合方程\tR2\tP值\t均值点\t生境\".split(\"\\t\")\n",
    "\n",
    "    for aa in range(7):\n",
    "        set_cell_border(\n",
    "        hdr_cells[aa],\n",
    "            top={\"sz\": 15,\"val\" : \"single\", \"color\": \"#000000\", \"space\": \"0\"},\n",
    "            bottom={\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},)\n",
    "        #  right={\"sz\": 0.25,\"val\" : \"dashed\", \"color\": \"#000000\", \"space\": \"0\"},\n",
    "        #     left={\"sz\": 0.25,\"val\" : \"dashed\", \"color\": \"#000000\", \"space\": \"0\"},)\n",
    "        \n",
    "    for i in range(7):\n",
    "        hdr_cells[i].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "        \n",
    "        run=hdr_cells[i].paragraphs[0].add_run(Fields[i],style = '宋')\n",
    "        run.font.size = Pt(9)\n",
    "        run.font.bold=True\n",
    "    \n",
    "    for dt in tabledata:\n",
    "        row_cells = table.add_row().cells\n",
    "        for g in range(7):\n",
    "            row_cells[g].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "            run=row_cells[g].paragraphs[0].add_run(str(dt[g]),style = \"新罗马\")\n",
    "            run.font.size = Pt(10.5)\n",
    "    \n",
    "    for g in range(7):\n",
    "\n",
    "        #看到这行报错信息，说明你的类型csv名字没对上或者缺了\n",
    "        set_cell_border(\n",
    "        row_cells[g],\n",
    "\n",
    "            bottom={\"sz\": 15, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},)\n",
    "        #  right={\"sz\": 0.25,\"val\" : \"dashed\", \"color\": \"#000000\", \"space\": \"0\"},\n",
    "        #     left={\"sz\": 0.25,\"val\" : \"dashed\", \"color\": \"#000000\", \"space\": \"0\"},)\n",
    "    table.cell(0,0).width = Cm(1.5)\n",
    "    table.cell(0,1).width = Cm(1.5)\n",
    "    table.cell(0,2).width = Cm(4.5)\n",
    "    table.cell(0,3).width = Cm(1)\n",
    "    table.cell(0,4).width = Cm(1)\n",
    "    table.cell(0,5).width = Cm(3)\n",
    "    table.cell(0,6).width = Cm(1)\n",
    "    \n",
    "    \n",
    "    \n",
    "    #对类型的阐述\n",
    "    for typ in typelist:\n",
    "        df = pd.read_csv(typ,engine='python')\n",
    "        newname = changetypecsv(typ.split(\"\\\\\")[-1][:-4])\n",
    "        lines = []\n",
    "        for j in filelist:\n",
    "            if newname + \".svg\" in j:\n",
    "                with open(j, 'r',encoding = \"utf8\") as f:\n",
    "                    c = f.read()\n",
    "                    lines = re.findall(\"<!-- (E=.*?) -->\",c) + re.findall(\"<!-- (TB=.*?) -->\",c)\n",
    "                break\n",
    "\n",
    "\n",
    "        \"\"\"text = f\"群丛{newname}共计{len(df)}个样本点，如图{piccode+1}所示，\"\n",
    "        para = add(document,\"char\",text,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "        \n",
    "        if len(lines )> 1:\n",
    "            text = f\"【【拟合线太多没想好这里怎么写】】\"\n",
    "            para = add(document,\"char\",text,addto = para,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "        else:\n",
    "            g = \"正\" if \"E=-\" not in lines[0] else \"负\"\n",
    "            text = f\"TB和E之间呈显著{g}相关（P＜0.05）\"\n",
    "            para = add(document,\"char\",text,addto = para,charsize = 12,style = \"宋\")\n",
    "            \n",
    "            a,b = round(sum(df[\"tb\"])/len(df),2),round(sum(df[\"E_sum\"])/len(df),2)\n",
    "            text = f\"，线性拟合方程为{lines[0]}，均值点为（{a},{b}），\"\n",
    "            para = add(document,\"char\",text,addto = para,charsize = 12,style = \"宋\")\n",
    "        \n",
    "        text = f\"主要分布于{bandname}范围内的【【？】】下，PE/P的值大于【【？】】，表示该群丛处于【【？】】。\"\n",
    "        add(document,\"char\",text,addto = para,charsize = 12,style = \"宋\")\n",
    "        \n",
    "        \n",
    "        add(document,\"pic\",占位图路径,picsize = (10,6),mid = True)\n",
    "        text = f\"图{piccode} 群丛{newname} TB-E坐标系分布图\"\n",
    "        piccode += 1\n",
    "        add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "        \"\"\"\n",
    " ############################################################################       \n",
    "        for c in filelist:\n",
    "            a = newname.split(\"-\")[-1]\n",
    "            if c.endswith(f\"{bandname}_地域{areacode}_类型{a}_演替.csv\"):\n",
    "                df = pd.read_csv(c,engine='python')\n",
    "                break\n",
    "        breaksign = False\n",
    "        ldm_data=[]########\n",
    "        for i in range(len(df)):\n",
    "            total = 0\n",
    "            for a in [0,1,2]:\n",
    "                for b in [1,2,3]:\n",
    "                    try:\n",
    "                        total += int(df[f\"c1={a}&c2={b}\"][i])\n",
    "                    except:\n",
    "                        breaksign = True\n",
    "            if breaksign:\n",
    "                break\n",
    "            if str(df[\"value\"][i]) in reverse:\n",
    "                rev = reverse[str(int(df[\"value\"][i]))]\n",
    "            else:\n",
    "                rev = \"\"\n",
    "            ld = [int(df[\"value\"][i]),rev,\n",
    "                  str(round(float(df[\"c1=0&c2=3\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=1&c2=1\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=2&c2=1\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=1&c2=2\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=2&c2=2\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=1&c2=3\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=2&c2=3\"][i])*100/total,2))+\"%\",\n",
    "                 ]\n",
    "            ldm_data.append(ld)\n",
    "            \n",
    "            #row_cells = table.add_row().cells\n",
    "        ldm_data=pd.DataFrame(ldm_data)######\n",
    "        zhibei_csv=pd.read_excel(zhibei_total)\n",
    "        wanquan=pd.merge(ldm_data,zhibei_csv,how='left',left_on=0,right_on='value')\n",
    "        #1删自己\n",
    "        wanquan =  wanquan.drop(index = wanquan[(wanquan[1] ==空间分布mxd名字.split('_')[0])].index.tolist())\n",
    "        #2df[\"FamilyName\"]=df[\"Name\"].map(lambda x: x.split(\",\")[0].strip())\n",
    "        wanquan[2] = wanquan[2].map(lambda x:float(x.split('%')[0].strip()))\n",
    "        total='根据表中数据所得，'\n",
    "        total_1='综上所述,'\n",
    "        total=str(total)\n",
    "        if wanquan[2].max()>=63.21:\n",
    "            total=total+creat_name(wanquan[wanquan[2]>=63.21])+'稳态占比大于63.21%，'\n",
    "            total_1=total_1+空间分布mxd名字.split('_')[0]+空间分布mxd名字.split('_')[1]+'侵占'+creat_name(wanquan[wanquan[2]>=63.21])+'概率很大，'\n",
    "            if len(wanquan[(wanquan[2]<63.21) & (wanquan[2]>=36.79)])>0:\n",
    "                total=total+creat_name(wanquan[(wanquan[2]<63.21) & (wanquan[2]>=36.79)])+'稳态占比大于36.79%小于63.21%，'\n",
    "                total_1=total_1+'侵占'+creat_name(wanquan[(wanquan[2]<63.21) & (wanquan[2]>=36.79)])+'概率较大，'\n",
    "            if len(wanquan[wanquan[2]<36.79]):\n",
    "                total=total+creat_name(wanquan[wanquan[2]<36.79])+'稳态占比小于36.79%，'\n",
    "                total_1=total_1+'侵占'+creat_name(wanquan[wanquan[2]<36.79])+'概率较小，'\n",
    "            total=total.strip('，')\n",
    "            total_1=total_1.strip('，')\n",
    "            total=total+'。'+total_1+'。'\n",
    "\n",
    "        if wanquan[2].max()<63.21 and wanquan[2].max()>=36.79:\n",
    "            total=total+creat_name(wanquan[(wanquan[2]<63.21) & (wanquan[2]>=36.79)])+'稳态占比大于36.79%小于63.21%，'\n",
    "            total_1=total_1+'侵占'+creat_name(wanquan[(wanquan[2]<63.21) & (wanquan[2]>=36.79)])+'概率较大，'\n",
    "            if len(wanquan[wanquan[2]<36.79]):\n",
    "                total=total+creat_name(wanquan[wanquan[2]<36.79])+'稳态占比小于36.79%，'\n",
    "                total_1=total_1+'侵占'+creat_name(wanquan[wanquan[2]<36.79])+'概率较小，'\n",
    "            total=total.strip('，')\n",
    "            total_1=total_1.strip('，')\n",
    "            total=total+'。'+total_1+'。'\n",
    "        if wanquan[2].max()<36.79:\n",
    "            total=total+creat_name(wanquan[wanquan[2]<36.79])+'稳态占比小于36.79%，'\n",
    "            total_1=total_1+'侵占'+creat_name(wanquan[wanquan[2]<36.79])+'概率较大，'\n",
    "            total=total.strip('，')\n",
    "            total_1=total_1.strip('，')\n",
    "            total=total+'。'+total_1+'。'\n",
    "        if wanquan[2].max()==0:\n",
    "            total='自己写！！！！！！！！'\n",
    "        #ldm_data.to_excel(r\"E:\\chengxu\\arcpy-master\\论文\\999.xlsx\")######      \n",
    "        ##############################################################################\n",
    "        \n",
    "        text = f\"群丛{newname}的演替概率如表{tablecode}所示。表{tablecode}列举了该区域内各群系样本点状态的占比，对应分布情况如图{piccode}所示。\"+total\n",
    "        add(document,\"char\",text,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "        pic = 占位图路径\n",
    "        for c in filelist:\n",
    "            a = newname.split(\"-\")[-1]\n",
    "            if c.endswith(f\"{bandname}_地域{areacode}_类型{a}_演替.png\") or c.endswith(f\"{bandname}_地域{areacode}_类型{a}_演替图.png\"):\n",
    "                img = Image.open(c)\n",
    "                c = img.resize((int(img.size[0]*压缩比例),int(img.size[1]*压缩比例)))\n",
    "                c.save(\"temp.png\")\n",
    "                pic1 = \"temp.png\"\n",
    "                break\n",
    "        add(document,\"pic\",pic1,picsize = (13,8.5),mid = True)\n",
    "        text = f\"图{piccode} 群丛{newname}演替图\"\n",
    "        piccode += 1\n",
    "        add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "\n",
    "        text = f\"表{tablecode} 群丛{newname}演替图稳态分析\"\n",
    "        tablecode += 1\n",
    "        add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "\n",
    "        table = document.add_table(rows=1, cols=9,style=None)\n",
    "        table.alignment=WD_TABLE_ALIGNMENT.CENTER\n",
    "\n",
    "        #写标题行，并设置字体\n",
    "        hdr_cells = table.rows[0].cells\n",
    "        Fields=\"value\t说明书编号\t其余点\t95%内&稳态\t95%外&稳态\t95%内&亚稳态\t95%外&亚稳态\t95%内&混沌态\t95%外&混沌态\".split(\"\\t\")\n",
    "\n",
    "        for aa in range(9):\n",
    "            set_cell_border(\n",
    "            hdr_cells[aa],\n",
    "            top={\"sz\": 15,\"val\" : \"single\", \"color\": \"#000000\", \"space\": \"0\"},\n",
    "            bottom={\"sz\": 10, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},)\n",
    "\n",
    "        for i in range(9):\n",
    "            hdr_cells[i].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "\n",
    "            run=hdr_cells[i].paragraphs[0].add_run(Fields[i],style = '宋')\n",
    "            run.font.size = Pt(10.5)\n",
    "            run.font.bold=True\n",
    "        print(f\"{bandname}_地域{areacode}_类型{a}_演替.csv\")\n",
    "        for c in filelist:\n",
    "            a = newname.split(\"-\")[-1]\n",
    "            if c.endswith(f\"{bandname}_地域{areacode}_类型{a}_演替.csv\"):\n",
    "                df = pd.read_csv(c,engine='python')\n",
    "                break\n",
    "        breaksign = False\n",
    "        ldm_data=[]########\n",
    "        for i in range(len(df)):\n",
    "            total = 0\n",
    "            for a in [0,1,2]:\n",
    "                for b in [1,2,3]:\n",
    "                    try:\n",
    "                        total += int(df[f\"c1={a}&c2={b}\"][i])\n",
    "                    except:\n",
    "                        breaksign = True\n",
    "            if breaksign:\n",
    "                break\n",
    "            if str(df[\"value\"][i]) in reverse:\n",
    "                rev = reverse[str(int(df[\"value\"][i]))]\n",
    "            else:\n",
    "                rev = \"\"\n",
    "            ld = [int(df[\"value\"][i]),rev,\n",
    "                  str(round(float(df[\"c1=0&c2=3\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=1&c2=1\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=2&c2=1\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=1&c2=2\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=2&c2=2\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=1&c2=3\"][i])*100/total,2))+\"%\",\n",
    "                  str(round(float(df[\"c1=2&c2=3\"][i])*100/total,2))+\"%\",\n",
    "                 ]\n",
    "            ldm_data.append(ld)\n",
    "            \n",
    "            row_cells = table.add_row().cells\n",
    "            for g in range(9):\n",
    "                row_cells[g].paragraphs[0].paragraph_format.alignment=WD_ALIGN_PARAGRAPH.CENTER\n",
    "                run=row_cells[g].paragraphs[0].add_run(str(ld[g]),style = \"新罗马\")\n",
    "                run.font.size = Pt(10.5)\n",
    "   \n",
    "        for g in range(9):\n",
    "            #看到这行报错信息，就是没找着演替csv，少了或者名字没对上\n",
    "            set_cell_border(\n",
    "                row_cells[g],\n",
    "            bottom={\"sz\": 15, \"val\" : \"single\",\"color\": \"#000000\", \"space\": \"0\"},)\n",
    "        table.cell(0,0).width = Cm(1.15)\n",
    "        table.cell(0,1).width = Cm(1.5)\n",
    "        table.cell(0,2).width = Cm(1.5)\n",
    "        for i in range(3,5):\n",
    "            table.cell(0,i).width = Cm(1.7)\n",
    "        for i in range(5,9):\n",
    "            table.cell(0,i).width = Cm(1.96)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "110e395d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "预计会运行以下温度带： 暖温带、极地苔原带-寒温带-中温带-暖温带交错带\n",
      "暖温带地域1\n",
      "4-1-1\n",
      "暖温带_地域1_类型1_演替.csv\n",
      "极地苔原带-寒温带-中温带-暖温带交错带地域1\n",
      "1.2.3.4-1-1\n",
      "极地苔原带-寒温带-中温带-暖温带交错带_地域1_类型1_演替.csv\n",
      "end\n"
     ]
    }
   ],
   "source": [
    "from docx import Document\n",
    "from docx.shared import Cm, Pt\n",
    "from docx.document import Document as Doc\n",
    "from docx.oxml.ns import qn\n",
    "from docx.enum.style import WD_STYLE_TYPE\n",
    "from docx.enum.text import WD_PARAGRAPH_ALIGNMENT,WD_ALIGN_PARAGRAPH\n",
    "from docx.enum.table import WD_TABLE_ALIGNMENT\n",
    "from docx.shared import Inches\n",
    "from docx.oxml import OxmlElement\n",
    "import re\n",
    "from PIL import Image\n",
    "document = Document()\n",
    "\n",
    "style_song = document.styles.add_style('宋', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = '宋体'\n",
    "document.styles['宋']._element.rPr.rFonts.set(qn('w:eastAsia'), u'宋体')\n",
    "\n",
    "style_song = document.styles.add_style('黑', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = '黑体'\n",
    "document.styles['黑']._element.rPr.rFonts.set(qn('w:eastAsia'), u'黑体')\n",
    "\n",
    "style_song = document.styles.add_style('新罗马', WD_STYLE_TYPE.CHARACTER)\n",
    "style_song.font.name = 'Times new Roman'\n",
    "document.styles['新罗马']._element.rPr.rFonts.set(qn('w:eastAsia'), u'Times new Roman')\n",
    "\n",
    "piccode = 1\n",
    "tablecode = 1\n",
    "\n",
    "\n",
    "#大标题\n",
    "text = savecode + savename + \"的自组织格局与演替\"\n",
    "add(document,\"char\",text,charsize = 15,bold = True,style = \"黑\")\n",
    "\n",
    "#二标题\n",
    "text = \"1. 群丛的分布格局与演替\"\n",
    "add(document,\"char\",text,charsize = 15,bold = True,style = \"黑\")\n",
    "\n",
    "#小正文\n",
    "text = savename + \"广泛分布于我国西南，地形复杂，山岭与河谷之间气候差别很大。在一些高山峡谷区，从山下的热带气候到高山的亚寒带气候，垂直分带非常明显。由于高山峡谷区气候垂直变化显著。\"\n",
    "add(document,\"char\",text,charsize = 12,style = \"宋\",indent = 0.2)\n",
    "\n",
    "#图1 空间分布图\n",
    "pic = 占位图路径\n",
    "for i in filelist:\n",
    "    if \"scode_sname.png\" in i or \"scode_sname_空间分布.png\" in i or \"scode_sname_空间分布图.png\" in i:\n",
    "        img = Image.open(i)\n",
    "        c = img.resize((int(img.size[0]*压缩比例),int(img.size[1]*压缩比例)))\n",
    "        c.save(\"temp.png\")\n",
    "        pic = \"temp.png\"\n",
    "    elif savecode + \"_\" + savename + \".png\" in i or savecode + \"_\" + savename + \"_空间分布.png\" in i or savecode + \"_\" + savename + \"_空间分布图.png\" in i:\n",
    "        img = Image.open(i)\n",
    "        c = img.resize((int(img.size[0]*压缩比例),int(img.size[1]*压缩比例)))\n",
    "        c.save(\"temp.png\")\n",
    "        pic = \"temp.png\"\n",
    "        \n",
    "add(document,\"pic\",pic,picsize = (8,6.54),mid = True)\n",
    "\n",
    "text = f\"图{piccode} \" + savename + \"空间分布图\"\n",
    "piccode += 1\n",
    "add(document,\"char\",text,charsize = 10.5,style = \"宋\",mid = True)\n",
    "        \n",
    "    \n",
    "#对地域的阐述    \n",
    "bandlist = []\n",
    "for i in filelist:\n",
    "    if \"scode_sname\" in i.split(\"\\\\\")[-1] or savecode + \"_\" + savename  in i.split(\"\\\\\")[-1] :\n",
    "        try:\n",
    "            key = i.split(\"\\\\\")[-1].split(\".\")[0].split(\"_\")[2]\n",
    "        except:\n",
    "            continue\n",
    "        if  key not in bandlist and \"带\" in key and \"高\" not in key and \"分布\" not in key:\n",
    "            bandlist.append(key)\n",
    "def sortkey(char):\n",
    "    code = 0\n",
    "    tempr = ['交错带','极地苔原带','寒温带','中温带','暖温带','亚热带']\n",
    "    for index,temp in enumerate(tempr):\n",
    "        if temp in char:\n",
    "            code += 10**index\n",
    "    if \"交错带\" in char:\n",
    "        code += 10000000\n",
    "    if \"热带\" in char.replace(\"亚热带\",\"\"):\n",
    "        code += 10**7\n",
    "    return code\n",
    "\n",
    "for i in bandlist:\n",
    "    if i + \"交错带\" in bandlist:\n",
    "        bandlist.remove(i)\n",
    "        \n",
    "bandlist.sort(key = lambda x :sortkey(x))\n",
    "\n",
    "def sortkey(char):\n",
    "    code = 0\n",
    "    if \"_\" in char:\n",
    "        for i in char.split(\"_\")[-1][:-4].split(\".\"):\n",
    "            code += 10**int(i)\n",
    "    code += 1* int(char.split(\".\")[1])\n",
    "    code += 0.01 *int(char.split(\".\")[3])\n",
    "    return code\n",
    "\n",
    "\"\"\"typelist = []\n",
    "for i in filelist:\n",
    "    if \"类型csv\" in i and i.endswith(\".csv\"):\n",
    "        typelist.append(i.split(\"\\\\\")[-1])  \n",
    "typelist.sort(key = lambda x :sortkey(x) )\n",
    "   \n",
    "countl = [1,1,1,1,1,1,1,1,1]\n",
    "typedict = {}\n",
    "for i in typelist:\n",
    "    typedict[i] = i.split(\".\")[0] + \".\" + str(countl[int(i.split(\".\")[0])])\n",
    "    countl[int(i.split(\".\")[0])] += 1\n",
    "    \"\"\"\n",
    "print(\"预计会运行以下温度带：\" ,\"、\".join(i for i in bandlist))\n",
    "for band in bandlist:\n",
    "    temperature_template(band)\n",
    "    \n",
    "    \n",
    "document.save('test.docx') # 存储WORD文档\n",
    "print(\"end\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8dcdb9e0",
   "metadata": {},
   "source": [
    "# 恢复群丛文件夹 如果没改群系过长变量，那运行不运行都行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a3bc0f0e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def rep(st):\n",
    "    st = st.replace(\"scode\",savecode)\n",
    "    st = st.replace(\"sname\",savename)\n",
    "    st = st.replace(\"pcode\",polycode)\n",
    "    st = st.replace(\"pname\",polyname)\n",
    "    return st\n",
    "\n",
    "import os\n",
    "for root,dirs,files in os.walk(source_path,topdown=False): \n",
    "    for file in files:\n",
    "        filename_path=os.path.join(root,file)\n",
    "        new_filename = rep(file)\n",
    "        new_filename_path=os.path.join(root,new_filename)\n",
    "        try:\n",
    "            os.rename(filename_path,new_filename_path)\n",
    "        except:\n",
    "            print(\"重命名失败:\",filename_path)\n",
    "    for dir in dirs:\n",
    "        dir_path=os.path.join(root,dir)\n",
    "        new_dir = rep(dir)\n",
    "        new_dir_path=os.path.join(root,new_dir)\n",
    "        try:\n",
    "            os.rename(dir_path,new_dir_path)\n",
    "        except:\n",
    "            print(\"重命名失败:\",filename_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0387dd92",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
